package com.example.demo.huawei;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * @Author: liull
 * @Description: 输入两个字符串S L ,判断S是否是有效字串
 * 判定规则：
 * S中的每个字符在L中都能找到，可以不连续
 * 且S在L中的字符的前后顺序与S中顺序要保持一致
 * ace
 * abcde
 * 输出 4
 * @Date: Created in 16:15 2020/3/26
 * @Modified By:
 */
public class Main1 {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String s = br.readLine();
        String l = br.readLine();

        int indexS = 0;
        int indexL = 0;

        while (indexS < s.length() && indexL < l.length()) {
            if (s.charAt(indexS) == l.charAt(indexL)) {
                indexS++;
            }
            indexL++;
        }

        if (indexS == s.length()) {
            System.out.println(indexL - 1);
        } else
            System.out.println(-1);
//        for (int i = 0; i < s.length(); i++) {
//            for (int j = 0; j < l.length(); i++) {
//                if(s.charAt(i) == l.charAt(j)){
//                    ++i;
//                    ++j;
//                }
//            }
//        }

    }
}
